import request from '@/utils/request.js'
import { getToken, getUserId, getSiteId } from "@/utils/auth";
import { ElMessage } from 'element-plus';

/**
 * 
 * @param {Int} PictureType 
 * @param {String} Name 
 * @description 按图片类型,1:品牌名称,2:类型名称,3:用户名称
 * @param {File} img 
 * @returns 
 */
export function uploadImg(data = { PictureType: 1, Name: '', img: null }) {
  return new Promise((resolve, reject) => {
    request({
      url: '/PictureUploadV3/Post',
      method: 'post',
      data: {
        SiteId: getSiteId(),
        PictureType: data.PictureType || 1,
        Name: data.Name || '',
        img: data.img
      },
      headers: {
        isToken: false,
        repeatSubmit: false,
        'Content-Type': 'multipart/form-data'
      }
    }).then(res => {
      if (res.state) {
        resolve(res)
      } else {
        ElMessage.error('上传失败')
        reject(res)
      }
    }).catch(err => {
      reject(err)
    })
  })
}

/**
 * 
 * @param {String} Name 
 * @param {File} img 
 * @returns 
 */
export function uploadImg2(data = { Name: '', img: null }) {
  return new Promise((resolve, reject) => {
    request({
      url: '/PictureUpload2/Post',
      method: 'post',
      data: {
        SiteId: getSiteId(),
        Name: data.Name || '',
        img: data.img
      },
      headers: {
        isToken: false,
        repeatSubmit: false,
        'Content-Type': 'multipart/form-data'
      }
    }).then(res => {
      if (res.state) {
        resolve(res)
      } else {
        ElMessage.error('上传失败')
        reject(res)
      }
    }).catch(err => {
      reject(err)
    })
  })
}